package com.example.oop;

/**
 * 人员基类
 * 对比C#的类定义
 */
public class Person {
    // 私有字段 (类似C#的private字段)
    private String name;
    private int age;
    private String email;
    
    // 静态字段 (类似C#的static字段)
    public static int totalCount = 0;
    
    // 构造函数 (类似C#的构造函数)
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        totalCount++;
    }
    
    public Person(String name, int age, String email) {
        this(name, age); // 调用其他构造函数
        this.email = email;
    }
    
    // Getter方法 (类似C#的属性getter)
    public String getName() {
        return name;
    }
    
    public int getAge() {
        return age;
    }
    
    public String getEmail() {
        return email;
    }
    
    // Setter方法 (类似C#的属性setter)
    public void setName(String name) {
        this.name = name;
    }
    
    public void setAge(int age) {
        if (age >= 0) {
            this.age = age;
        }
    }
    
    public void setEmail(String email) {
        this.email = email;
    }
    
    // 实例方法
    public void introduce() {
        System.out.println("我叫 " + name + "，今年 " + age + " 岁");
        if (email != null && !email.isEmpty()) {
            System.out.println("邮箱: " + email);
        }
    }
    
    // 静态方法 (类似C#的static方法)
    public static int getTotalCount() {
        return totalCount;
    }
    
    // 重写toString方法 (类似C#的ToString())
    @Override
    public String toString() {
        return "Person{name='" + name + "', age=" + age + ", email='" + email + "'}";
    }
    
    // 重写equals方法 (类似C#的Equals())
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        
        Person person = (Person) obj;
        return age == person.age && 
               (name != null ? name.equals(person.name) : person.name == null) &&
               (email != null ? email.equals(person.email) : person.email == null);
    }
    
    // 重写hashCode方法
    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + age;
        result = 31 * result + (email != null ? email.hashCode() : 0);
        return result;
    }
} 